/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.enterprise.web;

import com.assg2.dao.DaoViewer;
import com.movie.Viewer;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Kevin
 */
public class FriendListCommand implements Command {

    public FriendListCommand() {
    }

    public String execute(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        //TODO: set the response content type to "text/html" here
        //TODO: You'll have to use getWriter() to output some HTML texts
        //TODO: close the output stream

        response.setContentType("text/html");// from response, set content type
        PrintWriter out = response.getWriter();// from response, get output writer     
        HttpSession session = request.getSession(true);
        Viewer user = (Viewer)session.getAttribute("user");
        DaoViewer dv = new DaoViewer();
        user = (Viewer)dv.findById(user.getIdviewer());
        Set friendSet = user.ListOfFriendsAccepted();
        if(friendSet.isEmpty()){
           request.setAttribute("message", "You have no friend yet. Maybe you want to <a href='searchFriend.jsp'>search friend</a>");
           return "/message.jsp";
        }else{
           request.setAttribute("friendList", friendSet);
           return "/friendList.jsp";
        }
        
    
    }
}